package myTest;

import index.Indexator;
import index.Indexator_WithPreliminarySorting;
import index.Indexator_WithTempFiles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;

import net.barashev.seclub.CmdLineOptions;
import net.barashev.seclub.corpus.Corpus;
import net.barashev.seclub.corpus.Document;
import net.barashev.seclub.corpus.MemoryCorpus;
import net.barashev.seclub.io.BufferManager;
import net.barashev.seclub.io.DataMarshaller;
import net.barashev.seclub.io.IteratingSlot;
import net.barashev.seclub.io.OutputSlot;
import net.barashev.seclub.io.Sorter;
import net.barashev.seclub.io.file.DiskFileManager;
import net.barashev.seclub.io.file.FileManager;
import net.barashev.seclub.io.file.MemoryFileManager;
import net.barashev.seclub.io.file.VFile;
import net.barashev.seclub.io.marshaller.IntegerComparator;
import net.barashev.seclub.io.marshaller.IntegerMarshaller;

public class CreateIndexForTestMemoryCorpus {

	public CreateIndexForTestMemoryCorpus() {
		
	
	}
	public static void main(String[] args) throws IOException, CmdLineException {
		System.out.println("START TEST_SE \n");
		CmdLineOptions options = new CmdLineOptions();
		CmdLineParser parser = new CmdLineParser(options);
		parser.parseArgument(args);  		

		Corpus corpus = getCorpus();

		DiskFileManager fileMgr = new DiskFileManager(Indexator_WithPreliminarySorting.CUR_DIRECTORY);
		System.out.println("Creating index in "
				+ fileMgr.getRoot().getAbsolutePath());
		BufferManager bufferMgr = new BufferManager(options.block_size_bytes,
				options.buffer_size_blocks);
		
		Indexator indexator = new Indexator_WithPreliminarySorting(corpus, fileMgr, bufferMgr, 48);
		indexator.index();
		
		/*fileMgr.createFile("waz", new IntegerMarshaller());
		fileMgr.createFile("bar", new IntegerMarshaller());
		fileMgr.createFile("zab", new IntegerMarshaller());
		fileMgr.createFile("sortingId", new IntegerMarshaller());*/
	}

	private static Corpus getCorpus() {
		TestMemoryCorpus corpus = new TestMemoryCorpus();
		corpus.addDocument(3, "bar zab waz", new int[] { 2, 1 });
		corpus.addDocument(5, "waz bar zab ", new int[] { 2, 1 });
		corpus.addDocument(4, "bar zab waz maz", new int[] { 1, 3 });
		corpus.addDocument(8, "bar bar baz  bar baz", new int[] { 2, 4 });
		corpus.addDocument(1, "bar baz bar baz bar", new int[] { 2, 4 });
		corpus.addDocument(6, "bar foo ", new int[] { 4 });
		corpus.addDocument(2, "foo bar", new int[] { 4 });
		corpus.addDocument(7, "zab bar waz maz", new int[] { 1, 3 });
		return corpus;
	}
}
